package com.mapaoer.user.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.baomidou.mybatisplus.annotation.*;
import java.time.LocalDateTime;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * 用户实体类
 * 表示系统中的用户，可以是开发者或企业用户
 */
@TableName("sys_user")
public class User {

    @TableId(type = IdType.AUTO)
    private Long id;

    @TableField(unique = true, nullable = false)
    private String username;

    @TableField(nullable = false)
    private String password;

    public List<String> getRoles() {
        return roles;
    }

    @TableField(unique = true, nullable = false)
    private String email;

    private String phone;

    // 第三方登录字段
    private String wechatOpenId;
    private String alipayUserId;
    private String smsCode;
    private Date smsCodeExpireTime;

    // 用户类型：DEVELOPER(开发者), ENTERPRISE(企业)
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private UserType type;

    // 会员状态：FREE(免费), PREMIUM(付费)
    @Enumerated(EnumType.STRING)
    private MembershipStatus membershipStatus;

    // 会员开始时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date membershipStartTime;

    // 会员结束时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date membershipEndTime;
    @Enumerated(EnumType.STRING)
    private UserType userType;

    // 最后登录时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lastLoginTime;

    // 账户状态：ACTIVE(活跃), LOCKED(锁定), DELETED(删除)
    @Enumerated(EnumType.STRING)
    private AccountStatus status;

    // 创建时间
    @TableField(fill = FieldFill.INSERT)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @TableField(fill = FieldFill.INSERT_UPDATE)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    // 用户角色关联
    // 角色ID集合
    @TableField(exist = false)
    private Set<Long> roleIds;

    // 用户类型枚举
    public enum UserType {
        DEVELOPER, ENTERPRISE
    }

    // 会员状态枚举
    public enum MembershipStatus {
        FREE, PREMIUM
    }

    // 账户状态枚举
    public enum AccountStatus {
        ACTIVE, LOCKED, DELETED
    }

    // Getter and Setter methods
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public UserType getType() {
        return type;
    }

    public void setType(UserType type) {
        this.type = type;
    }

    public MembershipStatus getMembershipStatus() {
        return membershipStatus;
    }

    public void setMembershipStatus(MembershipStatus membershipStatus) {
        this.membershipStatus = membershipStatus;
    }

    public Date getMembershipStartTime() {
        return membershipStartTime;
    }

    public void setMembershipStartTime(Date membershipStartTime) {
        this.membershipStartTime = membershipStartTime;
    }

    public Date getMembershipEndTime() {
        return membershipEndTime;
    }

    public void setMembershipEndTime(Date membershipEndTime) {
        this.membershipEndTime = membershipEndTime;
    }

    public UserType getUserType() {
        return userType;
    }

    public void setUserType(UserType userType) {
        this.userType = userType;
    }

    public Date getLastLoginTime() {
        return lastLoginTime;
    }

    public void setLastLoginTime(Date lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    public AccountStatus getStatus() {
        return status;
    }

    public void setStatus(AccountStatus status) {
        this.status = status;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public LocalDateTime getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(LocalDateTime updateTime) {
        this.updateTime = updateTime;
    }

    // 第三方登录字段的getter和setter
    public String getWechatOpenId() {
        return wechatOpenId;
    }

    public void setWechatOpenId(String wechatOpenId) {
        this.wechatOpenId = wechatOpenId;
    }

    public String getAlipayUserId() {
        return alipayUserId;
    }

    public void setAlipayUserId(String alipayUserId) {
        this.alipayUserId = alipayUserId;
    }

    public String getSmsCode() {
        return smsCode;
    }

    public void setSmsCode(String smsCode) {
        this.smsCode = smsCode;
    }

    public Date getSmsCodeExpireTime() {
        return smsCodeExpireTime;
    }

    public void setSmsCodeExpireTime(Date smsCodeExpireTime) {
        this.smsCodeExpireTime = smsCodeExpireTime;
    }
}